Skip to content

fix(interpreter): add depth limit to extglob pattern matching#447

Merged
chaliy merged 2 commits intomainfrom
claude/fix-409-Y2nIj
Mar 1, 2026
Merged

fix(interpreter): add depth limit to extglob pattern matching#447
chaliy merged 2 commits intomainfrom
claude/fix-409-Y2nIj

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Mar 1, 2026

Summary

  • Add MAX_GLOB_DEPTH=50 constant to prevent unbounded recursion
  • Add depth parameter to glob_match_impl() and match_extglob()
  • Update all 23 recursive call sites to propagate depth
  • Returns false (no match) when depth exceeded

Test plan

  • 1 new test: extglob +(a|aa) against "aaaaaaaaaaaa" completes in <5s
  • All 1432 existing tests pass
  • clippy clean

Closes #409

@chaliy chaliy force-pushed the claude/fix-409-Y2nIj branch 2 times, most recently from a198056 to 1d6d7d1 Compare March 1, 2026 07:42
claude added 2 commits March 1, 2026 07:51
THREAT[TM-DOS-031]: The +(...)  and *(...) extglob handlers in
match_extglob recursively call glob_match_impl without any depth
limit. For each split point in the string, the function recurses
with a reconstructed pattern, creating O(n!) time complexity.

Add a MAX_GLOB_DEPTH (50) constant and depth parameter to both
glob_match_impl and match_extglob. All recursive calls pass
depth + 1, and both functions bail early returning false when
the limit is exceeded.

Closes #409

https://claude.ai/code/session_01WZjYqxm5xMPAEe7FSHJkDy
@chaliy chaliy force-pushed the claude/fix-409-Y2nIj branch from 1d6d7d1 to 99bd196 Compare March 1, 2026 07:51
@chaliy chaliy merged commit 15fd62e into main Mar 1, 2026
17 checks passed
@chaliy chaliy deleted the claude/fix-409-Y2nIj branch March 12, 2026 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[H-3] Unbounded recursion in extglob pattern matching (DoS)

2 participants